﻿using System.Security.Claims;

namespace GSOrganization.Application;

public class BaseService
    {
        public string UserId
        {
            get
            {
                var userId = Furion.App.User?.FindFirstValue(ClaimTypes.Sid);
                if (string.IsNullOrWhiteSpace(userId))
                    userId = Furion.App.User?.FindFirstValue("UserId");
                return userId;
            }
        }
        public string UserName
        {
            get
            {
                var name = Furion.App.User?.FindFirstValue(ClaimTypes.Name);
                if (string.IsNullOrWhiteSpace(name))
                    name = Furion.App.User?.FindFirstValue("UserName");
                return name;
            }
        }
        /// <summary>
        /// 不推荐使用该方法获取用户信息
        /// </summary>
        public MyCurrentUser CurrUser
        {
            get
            {
                var user = Furion.App.User?.FindFirstValue(ClaimTypes.UserData);
                if (string.IsNullOrWhiteSpace(user))
                    user = Furion.App.User?.FindFirstValue("UserData");

                if (!string.IsNullOrWhiteSpace(user))
                {
                    return Newtonsoft.Json.JsonConvert.DeserializeObject<MyCurrentUser>(user);
                }
                else
                {
                    return null;
                }
            }
        }
    }
